package com.gzpi.hwgggh.controller;

import com.gzpi.hwgggh.service.DWXService;
import com.gzpi.hwgggh.sysenum.EnumErrorCode;
import com.gzpi.hwgggh.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @date : 2021-01-11 16:46
 **/
@RestController
@RequestMapping("/DWX")
@CrossOrigin
public class DWXController {

    @Autowired
    private DWXService dwxService;

    @RequestMapping("/batchRemoveDW")
    public Result removeDWX(String dwbhs,HttpServletRequest request){
        try {
            return dwxService.deleteDWX(dwbhs,request);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString(e.toString()));
        }
    }

    @RequestMapping("/removeDWX")
    public Result removeDWXByID(String id, HttpServletRequest request){
        try {
            return dwxService.deleteDWXByID(id, request);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString(e.toString()));
        }
    }

    @RequestMapping("/addDW")
    public Result addDW(String dwxJson,@RequestParam(value = "files",required = false) MultipartFile[] files,HttpServletRequest request){
        try {
            return dwxService.insertDW(dwxJson,files,request);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString(e.toString()));
        }
    }

    @RequestMapping("/uploadCropped")
    public Result uploadCropped(String id,@RequestParam(value = "file",required = false)MultipartFile file,HttpServletRequest request){
        try {
            return dwxService.uploadCropped(id,file,request);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString(e.toString()));
        }
    }

}
